package Eyjafjalla.action;

import Eyjafjalla.card.status.Burn_Eyjafjalla;
import Eyjafjalla.patch.CloudPatch;
import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.cards.status.Burn;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;

import java.util.ArrayList;

public class UpgradeAllBurnAction extends AbstractGameAction {
    public UpgradeAllBurnAction(int times){
        this.amount = times;
    }

    @Override
    public void update() {
        AbstractPlayer p = AbstractDungeon.player;
        upgradeGroup(p.drawPile.group);
        upgradeGroup(p.discardPile.group);
        upgradeGroup(p.hand.group);
        upgradeGroup(CloudPatch.cloudGroup.group);
        this.isDone = true;
    }

    private void upgradeGroup(ArrayList<AbstractCard> group){
        AbstractCard c;
        for(int i =0;i< group.size();i++){
            c = group.get(i);
            if(c instanceof Burn_Eyjafjalla){
                for(int j = 0;j<this.amount;j++)
                    c.upgrade();
                c.flash();
            }
            else if(c instanceof Burn){
                AbstractCard burnE = new Burn_Eyjafjalla();
                if(c.upgraded)
                    burnE.upgrade();
                for(int j = 0;j<this.amount;j++)
                    burnE.upgrade();
                group.set(i,burnE);
                burnE.flash();
            }
        }
    }
}
